package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.News;
import server.NewsServer;
import serverImp.NewsServerImp;

public class ListServlet extends HttpServlet {

	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		NewsServer ns=new NewsServerImp();
		List<News>list=ns.query();
		if(list!=null&list.size()>0){
			request.getSession().setAttribute("list", list);
			response.sendRedirect("newslist.jsp");
		}else{
			response.sendRedirect("newslist.jsp");
		}
	}

}
